//
//  NSDate+Cool.m
//  HX2Car
//
//  Created by Mudmen on 2018/9/17.
//  Copyright © 2018年 Hx2car_mac. All rights reserved.
//

#import "NSDate+Cool.h"

@implementation NSDate (Cool)

/**
 *  是否为同一天
 */
+ (BOOL)isSameDay:(NSDate*)date1 date2:(NSDate*)date2
{
    NSCalendar* calendar = [NSCalendar currentCalendar];
    
    unsigned unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth |  NSCalendarUnitDay;
    NSDateComponents* comp1 = [calendar components:unitFlags fromDate:date1];
    NSDateComponents* comp2 = [calendar components:unitFlags fromDate:date2];
    
    return [comp1 day] == [comp2 day] &&
    [comp1 month] == [comp2 month] &&
    [comp1 year]  == [comp2 year];
}

+ (BOOL)isToday:(NSDate *)date
{
    if (!date) {
        return NO;
    }
    NSDate *today = [[NSDate alloc] init];
    NSString * todayString = [[today description] substringToIndex:10];
    NSString * dateString = [[date description] substringToIndex:10];
    if ([dateString isEqualToString:todayString])
    {
        return YES;
    }
    return NO;
}

@end
